package com.atguigu.flink.chapter11;

import com.atguigu.flink.bean.WaterSensor;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.Table;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import org.apache.flink.types.Row;

import static org.apache.flink.table.api.Expressions.$;

public class Flink09_Time_Processing {
       public static void main(String[] args) {
               Configuration configuration = new Configuration();
               //web  UI端口
               configuration.setInteger("rest.prot",10000);
               StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(configuration);
               env.setParallelism(1);

           DataStreamSource<WaterSensor> waterSensorStream =
           env.fromElements(new WaterSensor("sensor_1", 1000L, 10),
                   new WaterSensor("sensor_1", 2000L, 20),
                   new WaterSensor("sensor_2", 3000L, 30),
                   new WaterSensor("sensor_1", 4000L, 40),
                   new WaterSensor("sensor_1", 5000L, 50),
                   new WaterSensor("sensor_2", 6000L, 60));

           // 1. 创建表的执行环境
           StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);
           // 2. 创建表: 将流转换成动态表. 添加 时间属性 ，字段   proctime 处理时间

           //流 转成表的时候， 在schema 的某位添加一个新的字段，用来表示处理时间
           Table table = tableEnv.fromDataStream(waterSensorStream,$("id"),$("ts"),$("vc"),$("pt").proctime());

           table.execute().print();






           }
}
